package com.gc.asm.client.constans;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: yzj
 * @description: 通用常量枚举类, 单个业务的常量请单开一个类, 方便常量的分类管理
 * @date: 2018/07/17 10:15
 */
public enum ConstantsEnum {


    REQUEST_SUCCESS("100", "请求成功", EnumGroup.REQUEST_SUCCESS_COMMON),
    RESPONSE_E_AAAA("520100","请求失败",EnumGroup.RESPONSE_ERROR_COMMON),
    RESPONSE_E_AAAB("520101", "缺少必填参数",EnumGroup.RESPONSE_ERROR_COMMON),
    RESPONSE_E_AAAC("520102", "权限不足!",EnumGroup.RESPONSE_ERROR_COMMON),
    RESPONSE_E_AAAD("520103", "登录失败!",EnumGroup.RESPONSE_ERROR_COMMON),
    RESPONSE_E_BAAA("521100", "登录已过期,请重新登录!",EnumGroup.RESPONSE_ERROR_ASM),
    RESPONSE_E_BAAB("521101", "此帐户已在其他地方登录!",EnumGroup.RESPONSE_ERROR_ASM),
    RESPONSE_E_BAAC("521102", "登录失败，请您确认用户名输入是否正确!",EnumGroup.RESPONSE_ERROR_ASM),
    RESPONSE_E_BAAD("521103", "登录失败，登录密码不正确，请重新输入!",EnumGroup.RESPONSE_ERROR_ASM),
    RESPONSE_E_BAAE("521104", "当前登录密码输入错误次数超限，请次日再试!",EnumGroup.RESPONSE_ERROR_ASM),
    RESPONSE_E_BAAF("521105", "登录失败，您登录的账户已被禁用，请联系管理员!",EnumGroup.RESPONSE_ERROR_ASM),
    RESPONSE_E_BAAG("521106", "未登录",EnumGroup.RESPONSE_ERROR_ASM),

    API_REQUEST_NUMBER_EXCEEDED("request_number_exceeded", "请求次数已超出最大请求次数",EnumGroup.API_ERROR),
    API_AUTH_INTERFACE_INVALID("auth_interface_invalid", "授权接口无效",EnumGroup.API_ERROR),
    API_AUTH_INVALID("auth_invalid", "授权码无效",EnumGroup.API_ERROR),
    API_AUTH_IS_NULL("auth_is_null", "授权码为空",EnumGroup.API_ERROR),
    API_REQUEST_IP_IS_NULL("request_ip_is_null", "请求IP为空",EnumGroup.API_ERROR),
    API_AUTH_IP_INVALID("auth_ip_invalid", "授权IP无效",EnumGroup.API_ERROR);

    private String key;
    private String value;
    private EnumGroup enumGroup;


    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public EnumGroup getEnumGroup() {
        return enumGroup;
    }

    ConstantsEnum(String key, String value, EnumGroup enumGroup) {
        this.key = key;
        this.value = value;
        this.enumGroup = enumGroup;
    }

    /**
     * 获取指定分组下的所有枚举信息
     *
     * @param enumGroup
     * @return
     */
    public static Map<String, String> getEnum(EnumGroup enumGroup) {
        Map<String, String> options = new HashMap();
        for (ConstantsEnum e : ConstantsEnum.values()) {
            if (e.getEnumGroup().equals(enumGroup)) {
                options.put(e.getKey(), e.getValue());
            }
        }
        return options;
    }

    /**
     * 根据枚举Key与分组对象获取Value
     * @param key
     * @param enumGroup
     * @return
     */
    public static String getValue(String key, EnumGroup enumGroup){
        for (ConstantsEnum e : ConstantsEnum.values()){
            if(e.getKey().equals(key) && e.getEnumGroup().equals(enumGroup)){
                return e.getValue();
            }
        }
        return null;
    }
}
